package logic

import (
	"2210a/commod/commodrpc/commodrpc"
	"2210a/commod/commodrpc/internal/svc"
	mysql "2210a/commod/models/mysql"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopShowLogic {
	return &ShopShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopShowLogic) ShopShow(in *commodrpc.ShopShowRequest) (*commodrpc.ShopShowResponse, error) {
	// todo: add your logic here and delete this line
	var FindProduct mysql.Products
	mysql.Db.Where("id = ?", in.Id).Find(&FindProduct)
	if FindProduct.ID == 0 {
		return nil, fmt.Errorf("商品不存在，详情失败")
	}
	if FindProduct.UserId != in.UserId {
		return nil, fmt.Errorf("用户不存在，详情失败")
	}
	//products := mysql.Products{
	//	Model:  gorm.Model{ID: uint(in.Id)},
	//	UserId: in.UserId,
	//}
	return &commodrpc.ShopShowResponse{
		Id:             int64(FindProduct.ID),
		UserId:         FindProduct.UserId,
		Avatar:         FindProduct.Avatar,
		ShopName:       FindProduct.ShopName,
		Price:          FindProduct.Price,
		Gender:         FindProduct.Gender,
		ShopNavigation: FindProduct.ShopNavigation,
		Address:        FindProduct.Address,
		Quantity:       FindProduct.Quantity,
		Introduce:      FindProduct.Introduce,
		Status:         FindProduct.Status,
	}, nil
}
